package com.sky.controller.user;


import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
@Api("添加购物车")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @ApiOperation("购物车接口")
    @PostMapping("/add")
    public Result addSshopping(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("[接受下单的菜品ID]DTO:{}",shoppingCartDTO);
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    @ApiOperation("查看购物车")
    @GetMapping("list")
    public Result<List<ShoppingCart>> getShoppingCart(){

        List<ShoppingCart> shoppingCart = shoppingCartService.getShoppingCart();
      return  Result.success(shoppingCart);
    }
    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result deleteShopping(){
        shoppingCartService.deleteShopping();
        return Result.success();
    }
}
